/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { sha256, sha224, hmacSha224, hmacSha256 } from "./sha256.js";
import { imageData } from "./imageData.js";

let key = 'kJeZr6b2u3*mABFB'
let content = 'ABCDEFGHIJKabcdefj123456+/AA==!@一段中文';
let contentArray = []
let uin8Array = new Uint8Array(imageData)
let content1k = ""
let content5k = ""
let contentArray1k = []
let contentArray5k = []
for (let i = 0; i < content.length; i++) {
    contentArray.push(content[i]);
}
let dic = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]
for (let i = 0; i < 1024; i++) {
    content1k += dic[i / 10]
    contentArray1k.push(dic[i / 10])
}
let num = 5120
for (let i = 0; i < num; i++) {
    content5k += dic[i / 10]
    contentArray5k.push(dic[i / 10])
}

function sha256_Test_01() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 10000; i++) {
        result = sha256(content)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha256(string) error'
    }
    print(`sha256_sha256(string): ${endTime - startTime} ms`)
}

function sha256_Test_02() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 1000; i++) {
        result = sha256(content1k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha256(string1k) error'
    }
    print(`sha256_sha256(string1k): ${endTime - startTime} ms`)
}

function sha256_Test_03() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 100; i++) {
        result = sha256(content5k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha256(string5k) error'
    }
    print(`sha256_sha256(string5k): ${endTime - startTime} ms`)
}

function sha256_Test_04() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 10000; i++) {
        result = sha256(contentArray)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha256(Array) error'
    }
    print(`sha256_sha256(Array): ${endTime - startTime} ms`)
}

function sha256_Test_05() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 1000; i++) {
        result = sha256(contentArray1k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha256(Array1k) error'
    }
    print(`sha256_sha256(Array1k): ${endTime - startTime} ms`)
}

function sha256_Test_06() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 100; i++) {
        result = sha256(contentArray5k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha256(Array5k) error'
    }
    print(`sha256_sha256(Array5k): ${endTime - startTime} ms`)
}

function sha256_Test_07() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 1000; i++) {
        result = sha256(uin8Array)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha256(uin8Array) error'
    }
    print(`sha256_sha256(uin8Array): ${endTime - startTime} ms`)
}

function sha256_Test_08() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 10000; i++) {
        result = sha256.hex(content)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha256.hex(content) error'
    }
    print(`sha256_sha256.hex(string): ${endTime - startTime} ms`)
}

function sha256_Test_09() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 1000; i++) {
        result = sha256.hex(content1k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha256.hex(content1k) error'
    }
    print(`sha256_sha256.hex(string1k): ${endTime - startTime} ms`)
}

function sha256_Test_10() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 100; i++) {
        result = sha256.hex(content5k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha256.hex(content5k) error'
    }
    print(`sha256_sha256.hex(string5k): ${endTime - startTime} ms`)
}

function sha256_Test_11() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 10000; i++) {
        result = sha256.array(content)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha256.array(content) error'
    }
    print(`sha256_sha256.array(string): ${endTime - startTime} ms`)
}

function sha256_Test_12() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 1000; i++) {
        result = sha256.array(content1k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha256.array(content1k) error'
    }
    print(`sha256_sha256.array(string1k): ${endTime - startTime} ms`)
}

function sha256_Test_13() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 100; i++) {
        result = sha256.array(content5k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha256.array(content5k) error'
    }
    print(`sha256_sha256.array(string5k): ${endTime - startTime} ms`)
}

function sha256_Test_14() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 10000; i++) {
        result = sha256.digest(content)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha256.digest(content) error'
    }
    print(`sha256_sha256.digest(string): ${endTime - startTime} ms`)
}

function sha256_Test_15() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 1000; i++) {
        result = sha256.digest(content1k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha256.digest(content1k) error'
    }
    print(`sha256_sha256.digest(string1k): ${endTime - startTime} ms`)
}

function sha256_Test_16() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 100; i++) {
        result = sha256.digest(content5k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha256.digest(content5k) error'
    }
    print(`sha256_sha256.digest(string5k): ${endTime - startTime} ms`)
}

function sha256_Test_17() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 10000; i++) {
        result = sha256.arrayBuffer(content)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha256.arrayBuffer(content) error'
    }
    print(`sha256_sha256.arrayBuffer(string): ${endTime - startTime} ms`)
}

function sha256_Test_18() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 1000; i++) {
        result = sha256.arrayBuffer(content1k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha256.arrayBuffer(content1k) error'
    }
    print(`sha256_sha256.arrayBuffer(string1k): ${endTime - startTime} ms`)
}

function sha256_Test_19() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 100; i++) {
        result = sha256.arrayBuffer(content5k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha256.arrayBuffer(content5k) error'
    }
    print(`sha256_sha256.arrayBuffer(string5k): ${endTime - startTime} ms`)
}

function sha256_Test_20() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 10000; i++) {
        result = hmacSha256(key, content)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha256.hmac(content) error'
    }
    print(`sha256_hmacSha256(string): ${endTime - startTime} ms`)
}

function sha256_Test_21() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 1000; i++) {
        result = hmacSha256(key, content1k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha256.hmac(content1k) error'
    }
    print(`sha256_hmacSha256(string1k): ${endTime - startTime} ms`)
}

function sha256_Test_22() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 100; i++) {
        result = hmacSha256(key, content5k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha256.hmac(content5k) error'
    }
    print(`sha256_hmacSha256(string5k): ${endTime - startTime} ms`)
}

function sha256_Test_23() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 10000; i++) {
        result = sha224(content)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha224(string) error'
    }
    print(`sha256_sha224(string): ${endTime - startTime} ms`)
}

function sha256_Test_24() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 1000; i++) {
        result = sha224(content1k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha224(string1k) error'
    }
    print(`sha256_sha224(string1k): ${endTime - startTime} ms`)
}

function sha256_Test_25() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 100; i++) {
        result = sha224(content5k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha224(string5k) error'
    }
    print(`sha256_sha224(string5k): ${endTime - startTime} ms`)
}

function sha256_Test_26() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 10000; i++) {
        result = sha224(contentArray)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha224(Array) error'
    }
    print(`sha256_sha224(Array): ${endTime - startTime} ms`)
}

function sha256_Test_27() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 1000; i++) {
        result = sha224(contentArray1k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha224(Array1k) error'
    }
    print(`sha256_sha224(Array1k): ${endTime - startTime} ms`)
}

function sha256_Test_28() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 100; i++) {
        result = sha224(contentArray5k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha224(Array5k) error'
    }
    print(`sha256_sha224(Array5k): ${endTime - startTime} ms`)
}

function sha256_Test_29() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 1000; i++) {
        result = sha224(uin8Array)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha224(uin8Array) error'
    }
    print(`sha256_sha224(uin8Array): ${endTime - startTime} ms`)
}

function sha256_Test_30() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 10000; i++) {
        result = sha224.hex(content)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha224.hex(content) error'
    }
    print(`sha256_sha224.hex(string): ${endTime - startTime} ms`)
}

function sha256_Test_31() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 1000; i++) {
        result = sha224.hex(content1k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha224.hex(content1k) error'
    }
    print(`sha256_sha224.hex(string1k): ${endTime - startTime} ms`)
}

function sha256_Test_32() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 100; i++) {
        result = sha224.hex(content5k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha224.hex(content5k) error'
    }
    print(`sha256_sha224.hex(string5k): ${endTime - startTime} ms`)
}

function sha256_Test_33() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 10000; i++) {
        result = sha224.array(content)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha224.array(content) error'
    }
    print(`sha256_sha224.array(string): ${endTime - startTime} ms`)
}

function sha256_Test_34() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 1000; i++) {
        result = sha224.array(content1k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha224.array(content1k) error'
    }
    print(`sha256_sha224.array(string1k): ${endTime - startTime} ms`)
}

function sha256_Test_35() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 100; i++) {
        result = sha224.array(content5k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha224.array(content) error'
    }
    print(`sha256_sha224.array(string5k): ${endTime - startTime} ms`)
}

function sha256_Test_36() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 10000; i++) {
        result = sha224.digest(content)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha224.digest(content) error'
    }
    print(`sha256_sha224.digest(string): ${endTime - startTime} ms`)
}

function sha256_Test_37() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 1000; i++) {
        result = sha224.digest(content1k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha224.digest(content1k) error'
    }
    print(`sha256_sha224.digest(string1k): ${endTime - startTime} ms`)
}

function sha256_Test_38() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 100; i++) {
        result = sha224.digest(content5k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha224.digest(content5k) error'
    }
    print(`sha256_sha224.digest(string5k): ${endTime - startTime} ms`)
}

function sha256_Test_39() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 10000; i++) {
        result = sha224.arrayBuffer(content)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha224.arrayBuffer(content) error'
    }
    print(`sha256_sha224.arrayBuffer(string): ${endTime - startTime} ms`)
}

function sha256_Test_40() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 1000; i++) {
        result = sha224.arrayBuffer(content1k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha224.arrayBuffer(content1k) error'
    }
    print(`sha256_sha224.arrayBuffer(string1k): ${endTime - startTime} ms`)
}

function sha256_Test_41() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 100; i++) {
        result = sha224.arrayBuffer(content5k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha224.arrayBuffer(content5k) error'
    }
    print(`sha256_sha224.arrayBuffer(string5k): ${endTime - startTime} ms`)
}

function sha256_Test_42() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 10000; i++) {
        result = hmacSha224(key, content)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha224.hmac(content) error'
    }
    print(`sha256_hmacSha224(string): ${endTime - startTime} ms`)
}

function sha256_Test_43() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 1000; i++) {
        result = hmacSha224(key, content1k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha224.hmac(content1k) error'
    }
    print(`sha256_hmacSha224(string1k): ${endTime - startTime} ms`)
}

function sha256_Test_44() {
    let result = null
    let startTime = Date.now()
    for (let i = 0; i < 100; i++) {
        result = hmacSha224(key, content5k)
    }
    let endTime = Date.now()
    if (result == null) {
        throw 'sha224.hmac(content5k) error'
    }
    print(`sha256_hmacSha224(string5k): ${endTime - startTime} ms`)
}

sha256_Test_01()
sha256_Test_02()
sha256_Test_03()
sha256_Test_04()
sha256_Test_05()
sha256_Test_06()
sha256_Test_07()
sha256_Test_08()
sha256_Test_09()
sha256_Test_10()
sha256_Test_11()
sha256_Test_12()
sha256_Test_13()
sha256_Test_14()
sha256_Test_15()
sha256_Test_16()
sha256_Test_17()
sha256_Test_18()
sha256_Test_19()
sha256_Test_20()
sha256_Test_21()
sha256_Test_22()
sha256_Test_23()
sha256_Test_24()
sha256_Test_25()
sha256_Test_26()
sha256_Test_27()
sha256_Test_28()
sha256_Test_29()
sha256_Test_30()
sha256_Test_31()
sha256_Test_32()
sha256_Test_33()
sha256_Test_34()
sha256_Test_35()
sha256_Test_36()
sha256_Test_37()
sha256_Test_38()
sha256_Test_39()
sha256_Test_40()
sha256_Test_41()
sha256_Test_42()
sha256_Test_43()
sha256_Test_44()
